package cn.bytecollege.admin.controller;

import cn.bytecollege.admin.service.CategoryService;
import cn.bytecollege.admin.service.CuisineService;
import cn.bytecollege.common.constant.Resource;
import cn.bytecollege.common.entity.Category;
import cn.bytecollege.common.entity.Cuisine;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
@WebServlet(name = "CuisineFindController",value = "/admin/cuisineFind")
public class CuisineFindController extends HttpServlet {
    private CuisineService cuisineService=null;
    private CategoryService categoryService=null;
    public CuisineFindController() {
        cuisineService=new CuisineService();
        categoryService=new CategoryService();
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String id = request.getParameter("id");
        Integer cuisineId = Integer.valueOf(id);


        List<Category> list=categoryService.find();
        Cuisine cuisine=cuisineService.findById(cuisineId);
        request.setAttribute("list",list);
        request.setAttribute("cuisine",cuisine);
        request.getRequestDispatcher(Resource.PAGE_LOCATION+"/admin/cuisineUpdate.jsp").forward(request,response);


    }
}
